local hengjiang = fk.CreateSkill{
    name = "ld__hengjiang",
}

hengjiang:addEffect(fk.Damaged,{
    anim_type = "masochism",
    trigger_times = function(self, event, target, player, data)
      return data.damage
    end,
    can_trigger = function(self, _, target, player, _)
        if target ~= player or not player:hasSkill(hengjiang.name) then return false end
        local current = player.room.current
        return current ~= nil and not current.dead
      end,
    on_use = function(_, _, _, player, data)
        local room = player.room
        local target = room.current
        local nums = math.max(#target:getCardIds("e"), 1)
        if target ~= nil and not target.dead then
          room:doIndicate(player.id, {target.id})
          room:addPlayerMark(target, "@ld__hengjiang-turn", nums)
          room:addPlayerMark(target, MarkEnum.MinusMaxCardsInTurn, nums)
        end
      end
})

hengjiang:addEffect(fk.TurnEnd,{
    anim_type = "drawcard",
    is_delay_effect = true,
    can_trigger = function(_, _, target, player, _)
        if player.dead or player:usedSkillTimes(hengjiang.name) == 0 then return false end
        local room = player.room
        local discard_ids = {}
        room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
          if e.data.phase == Player.Discard then
            table.insert(discard_ids, {e.id, e.end_id})
          end
          return false
        end, Player.HistoryTurn)
        if #discard_ids > 0 then
          if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
            local in_discard = false
            for _, ids in ipairs(discard_ids) do
              if #ids == 2 and e.id > ids[1] and e.id < ids[2] then
                in_discard = true
                break
              end
            end
            if in_discard then
              for _, move in ipairs(e.data) do
                if move.from == target and move.moveReason == fk.ReasonDiscard then
                  for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                      return true
                    end
                  end
                end
              end
            end
            return false
          end, Player.HistoryTurn) > 0 then
            return false
          end
        end
        return true
      end,
      on_cost = Util.TrueFunc,
      on_use = function(self, event, target, player, data)
        local room = player.room
        local num = math.min(player.maxHp, 5) - player:getHandcardNum()
        if num > 0 then
        player:drawCards(num, hengjiang.name)
        end
      end,
})

Fk:loadTranslationTable{
    ["ld__hengjiang"] = "横江",
    [":ld__hengjiang"] = "当你受到1点伤害后，你可以令当前回合角色本回合手牌上限-X(X为其装备区里的牌数且至少为1)，"..
      "然后本回合结束时，若其未于本回合的弃牌阶段弃置过其手牌，你将手牌摸至体力上限。",
    ["@ld__hengjiang-turn"] = "横江",

    ["$ld__hengjiang1"] = "霸必奋勇杀敌，一雪夷陵之耻！",
    ["$ld__hengjiang2"] = "江横索寒，阻敌绝境之中！",
}

return hengjiang